home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / gnat-3.05- / gnat-3 / gnat-3.05-i486-linux-elf-bin / rts / 2scemasp.adb < prev    next >
Encoding:
Text File  |  1996-06-07  |  7.7 KB  |  182 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                SYSTEM.COMPILER_EXCEPTIONS.MACHINE_SPECIFICS              --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.4 $                             --
  10. --                         (SunOS, Solaris Version)                         --
  11. --                                                                          --
  12. --   Copyright (C) 1991,1992,1993,1994,1995 Free Software Foundation, Inc.  --
  13. --                                                                          --
  14. -- GNARL is free software; you can  redistribute it  and/or modify it under --
  15. -- terms of the  GNU General Public License as published  by the Free Soft- --
  16. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  17. -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  18. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  19. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  20. -- for  more details.  You should have  received  a copy of the GNU General --
  21. -- Public License  distributed with GNARL; see file COPYING.  If not, write --
  22. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  23. -- MA 02111-1307, USA.                                                      --
  24. --                                                                          --
  25. -- As a special exception,  if other files  instantiate  generics from this --
  26. -- unit, or you link  this unit with other files  to produce an executable, --
  27. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  28. -- covered  by the  GNU  General  Public  License.  This exception does not --
  29. -- however invalidate  any other reasons why  the executable file  might be --
  30. -- covered by the  GNU Public License.                                      --
  31. --                                                                          --
  32. -- GNARL was developed by the GNARL team at Florida State University. It is --
  33. -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
  34. -- State University (http://www.gnat.com).                                  --
  35. --                                                                          --
  36.  
  37. --  This file performs the system-dependent translation between machine
  38. --  exceptions and the Ada exceptions, if any, that should be raised when
  39. --  when they occur. This version works for SunOS and Solaris.
  40.  
  41. with Interfaces.C; use Interfaces.C;
  42.  
  43. with Interfaces.C.POSIX_RTE;
  44.  
  45. package body System.Compiler_Exceptions.Machine_Specifics is
  46.  
  47.    package RTE renames Interfaces.C.POSIX_RTE;
  48.  
  49.    ------------------------
  50.    -- Identify_Exception --
  51.    ------------------------
  52.  
  53.    --  This function identifies the Ada exception to be raised using
  54.    --  the information when the system received a synchronous signal.
  55.    --  Since this function is machine and OS dependent, different code
  56.    --  has to be provided for different target.
  57.  
  58.    --  Following code is intended for SunOS/Solaris on Sparcstation.
  59.  
  60.    function Identify_Exception
  61.      (Which              : System.Task_Primitives.Machine_Exceptions;
  62.       Info               : System.Task_Primitives.Error_Information;
  63.       Modified_Registers : Pre_Call_State) return Ada.Exceptions.Exception_Id
  64.    is
  65.  
  66.       SPARC_MAXREGWINDOW : constant := 31;
  67.  
  68.       type sc_spbuf_t is array (1 .. SPARC_MAXREGWINDOW) of System.Address;
  69.  
  70.       type sc_wbuf_t is array (1 .. SPARC_MAXREGWINDOW, 1 .. 16) of int;
  71.  
  72.       type sigcontext is record
  73.          sc_onstack : int;              -- sigstack state to restore
  74.          sc_mask    : int;              -- signal mask to restore
  75.          sc_sp      : System.Address;   -- sp to restore
  76.          sc_pc      : System.Address;   -- pc to restore
  77.          sc_npc     : System.Address;   -- next pc to restore
  78.          sc_psr     : int;              -- psr to restore
  79.          sc_g1      : int;              -- register that must be restored
  80.          sc_o0      : int;
  81.          sc_wbcnt   : int;              -- number of outstanding windows
  82.          sc_spbuf   : sc_spbuf_t;       -- sp's for each wbuf (in C is char *)
  83.          sc_wbuf    : sc_wbuf_t;        -- window save buf
  84.       end record;
  85.  
  86.       type sigcontext_ptr is access sigcontext;
  87.  
  88.       --  The above operations will be available as predefined operations on
  89.       --  the modula Address type in GNARL, since this package is a child of
  90.       --  System.
  91.  
  92.       FPE_INTOVF_TRAP   : constant int := 16#1#;  -- Int overflow
  93.       FPE_STARTSIG_TRAP : constant int := 16#2#;  -- process using fp
  94.       FPE_INTDIV_TRAP   : constant int := 16#14#; -- Int divide by zero
  95.       FPE_FLTINEX_TRAP  : constant int := 16#c4#; -- floating inexact result
  96.       FPE_FLTDIV_TRAP   : constant int := 16#c8#; -- floating divide by zero
  97.       FPE_FLTUND_TRAP   : constant int := 16#cc#; -- floating underflow
  98.       FPE_FLTOPERR_TRAP : constant int := 16#d0#; -- floating operand error
  99.       FPE_FLTOVF_TRAP   : constant int := 16#d4#; -- floating overflow
  100.  
  101.       --  Following is SIGILL generated by trap 5 instruction
  102.  
  103.       ILL_CHECK_TRAP    : constant int := 16#80# + 16#05#;
  104.  
  105.       function Pre_Call_To_Context is new
  106.         Unchecked_Conversion (Pre_Call_State, sigcontext_ptr);
  107.  
  108.  
  109.       Current_Exception : Ada.Exceptions.Exception_Id;
  110.  
  111.       context : sigcontext_ptr :=
  112.                   Pre_Call_To_Context (Modified_Registers);
  113.  
  114.       sig     : RTE.Signal := RTE.Signal (Which);
  115.  
  116.    begin
  117.  
  118.       --  As long as we are using a longjmp to return control to the
  119.       --  exception handler on the runtime stack, we are safe. The original
  120.       --  signal mask (the one we had before coming into this signal catching
  121.       --  function) will be restored by the longjmp. Therefore, raising
  122.       --  an exception in this handler should be a safe operation.
  123.  
  124.       case sig is
  125.  
  126.          when RTE.SIGFPE =>
  127.  
  128.             case Info.si_code is
  129.  
  130.                when FPE_INTDIV_TRAP   |
  131.                     FPE_FLTINEX_TRAP  |
  132.                     FPE_FLTDIV_TRAP   |
  133.                     FPE_FLTUND_TRAP   |
  134.                     FPE_FLTOVF_TRAP   |
  135.                     FPE_FLTOPERR_TRAP |
  136.                     FPE_INTOVF_TRAP   =>
  137.  
  138.                   Current_Exception := Constraint_Error_Id;
  139.  
  140.                when others =>
  141.                   pragma Assert (False, "Unexpected SIGFPE signal");
  142.                   null;
  143.  
  144.             end case;
  145.  
  146.          when RTE.SIGILL =>
  147.  
  148.             case Info.si_code is
  149.  
  150.                when ILL_CHECK_TRAP =>
  151.                   Current_Exception := Constraint_Error_Id;
  152.  
  153.                when others =>
  154.  
  155.                   pragma Assert (false, "Unexpected SIGILL signal");
  156.                   null;
  157.             end case;
  158.  
  159.          when RTE.SIGSEGV =>
  160.  
  161.          --  If the address that caused the error was in the first page, this
  162.          --  was caused by accessing a null pointer.
  163.  
  164.             if context.sc_o0 >= 0 and context.sc_o0 < 16#2000# then
  165.                Current_Exception := Constraint_Error_Id;
  166.  
  167.             else
  168.                Current_Exception := Storage_Error_Id;
  169.             end if;
  170.  
  171.          when others =>
  172.  
  173.             pragma Assert (false, "Unexpected signal");
  174.             null;
  175.       end case;
  176.  
  177.       return Current_Exception;
  178.  
  179.    end Identify_Exception;
  180.  
  181. end System.Compiler_Exceptions.Machine_Specifics;
  182.